< previous page page_287 next page >

Page 287
Visual Basicspecific portions, your code is no longer portable. If you ever move the SQL statements to another database engine (such as SQL Server), you must remove the Visual Basicspecific portions of the SQL statements and replace them with something else that will work with the database engine you are using. This will not be an issue if you plan to stick with the Microsoft Access Jet engine for all your database access.
Another possible drawback that you'll encounter if you use Visual Basicspecific syntax in your SQL statements is that of speed. Extensive use of Visual Basicspecific code within SQL statements results in a slight performance hit. The speed difference is minor, but it should be considered.
It is better to use as few Visual Basicspecific functions in your SQL statements as possible. You will not limit the portability of your code, and you will not suffer from unduly slow processing of the SQL statements.
Note.gif
You can't use user-defined functions within your SQL statements when you use the Microsoft Access Jet database engine from within Visual Basic. You can only use the built-in SQL functions and the predefined Visual Basic functions.

More SQL DML Statements
Now that you know how to create basic SQL SELECT_FROM statements and you know how to use the built-in SQL functions, return to the basic SELECT_FROM statement and add a few more enhancements to your SQL tool kit.
The DISTINCT and DISTINCTROW Clauses
There are times when you select data from a table that has more than one occurrence of the rows you are trying to collect. For example, you want to get a list of all the customers that have at least one order on file in the Orders table. The problem is that some customers have several orders in the table. You don't want to see those names appear more than once in your result set. You can use the DISTINCT keyword to make sure that you do not get duplicates of the same customer in your result set.
Enter and execute the following statement. As a test, execute the same SQL statement without the DISTINCT clause and compare the result sets. Refer to Figure 8.20 as an example.
SELECT DISTINCT AUID FROM Titles
   ORDER BY AUID

 
< previous page page_287 next page >

If you like this book, buy it!